{extend name="default/base/base_fuwu" /}
{block name="fuwu_main"}
<div class="dssc-form-default">
    <form method="post" enctype="multipart/form-data" id="my_store_form" onsubmit="ds_ajaxpost('my_store_form','url','{:url('fuwu_manage_info/base')}');return false;"  >

        <dl>
            <dt>{$Think.lang.fuwu_manage_organization_name_text[$o2o_fuwu_organization_info.o2o_fuwu_organization_type]}：</dt>
            <dd>
                <input type="text" value="{$o2o_fuwu_organization_info.o2o_fuwu_organization_name}" name="organization_name" class="text w400">
            </dd>
        </dl>

        <dl>
            <dt>头像{$Think.lang.ds_colon} </dt>
            <dd>
                <div class="dssc-upload-thumb store-avatar">
                    <p>
                        <img src="{if !empty($o2o_fuwu_organization_info.o2o_fuwu_organization_avatar)}{:get_o2o_fuwu_file($o2o_fuwu_organization_info.o2o_fuwu_organization_id,$o2o_fuwu_organization_info.o2o_fuwu_organization_avatar,'avatar')}{else}{:ds_get_pic(ATTACH_COMMON,$Think.config.ds_config.default_user_portrait)}{/if}" id="img_file" />
                    </p>
                </div>
                <div class="dssc-upload-btn"> 
                    <a href="javascript:void(0);">
                        <span><input type="file" hidefocus="true" size="1" class="input-file" name="file" id="file" /></span>
                        <p><i class="iconfont">&#xe733;</i>图片上传</p>
                    </a>
                </div>
            </dd>
        </dl>
        
        <dl>
            <dt>联系电话{$Think.lang.ds_colon}</dt>
            <dd>
                <input class="text w200" name="organization_phone" maxlength="20" type="text"  id="organization_phone" value="{$o2o_fuwu_organization_info.o2o_fuwu_organization_phone}" />
            </dd>
        </dl>
        <dl>
            <dt>{$Think.lang.fuwu_manage_organization_birthday_text[$o2o_fuwu_organization_info.o2o_fuwu_organization_type]}{$Think.lang.ds_colon}</dt>
            <dd>
                <p>
                    <input class="text w200" id='organization_birthday' name="organization_birthday" type="text"  value="{$o2o_fuwu_organization_info.o2o_fuwu_organization_birthday|date='Y-m-d'}" />
                </p>
                <p class="hint"></p>
            </dd>
        </dl>
        <dl>
            <dt>所在地区{$Think.lang.ds_colon}</dt>
            <dd>
                <span class="w400">
                    <div {if $Think.config.ds_config.mapak_type eq '2'}onclick="change_map()"{/if}>
                        <input name="organization_lng" id="longitude" value="{$o2o_fuwu_organization_info.o2o_fuwu_organization_lng}" type="hidden" />
                        <input name="organization_lat" id="latitude" value="{$o2o_fuwu_organization_info.o2o_fuwu_organization_lat}" type="hidden" />
                        <input type="hidden" value="{$o2o_fuwu_organization_info.o2o_fuwu_organization_city_id|default=''}" name="organization_city_id" id="_area_1">
                        <input type="hidden" value="{$o2o_fuwu_organization_info.o2o_fuwu_organization_region_id|default=''}" name="organization_region_id" id="_area">
                        <input type="hidden" name="organization_region_name" id="region" value="{$o2o_fuwu_organization_info.o2o_fuwu_organization_region_name|default=''}"/>
                    </div>
                </span>
            </dd>
        </dl>
        <dl>
            <dt>详细地址{$Think.lang.ds_colon}</dt>
            <dd>
                <input type="text" value="{$o2o_fuwu_organization_info.o2o_fuwu_organization_address}" name="organization_address" id="organization_address" class="text w400" {if $Think.config.ds_config.mapak_type eq '2'}onkeyup="local.search($(this).val());"{/if}>
                <!--{if $Think.config.ds_config.mapak_type neq '0'}-->
                <div id="allmap" style="width:530px;height: 350px;margin-top: 20px"></div>
                <!--{/if}-->
            </dd>
        </dl>
        <div class="bottom">
            <input type="submit" class="submit" value="{$Think.lang.ds_common_button_save}" />
        </div>
    </form>
</div>

<script type="text/javascript" src="{$Think.PLUGINS_SITE_ROOT}/ajaxfileupload.js"></script> 
<script src="{$Think.PLUGINS_SITE_ROOT}/mlselection.js"></script>
<!--{if $Think.config.ds_config.mapak_type eq '1'}-->
<script type="text/javascript">
        window._AMapSecurityConfig = {
            securityJsCode:"{$Think.config.ds_config.gaode_jscode}",
        }
</script>
<script type="text/javascript" src="//webapi.amap.com/maps?v=2.0&key={$Think.config.ds_config.gaode_ak}"></script>
<!--{/if}-->
<!--{if $Think.config.ds_config.mapak_type eq '2'}-->
<script type="text/javascript" src="{$Think.HTTP_TYPE}api.map.baidu.com/api?v=2.0&ak={$Think.config.ds_config.baidu_ak}"></script>
<!--{/if}-->
<script>
var local;
    var map;
    var lst_name='';

    function change_map(){
        var name=$("#region").val();

        if(name!='' && lst_name!=name){
            lst_name=name;
            map.setCurrentCity(name);
            map.centerAndZoom(name,16);
            map.clearOverlays();
            local.search(name);
        }

    }
    $(function(){
		var lng = '{$o2o_fuwu_organization_info.o2o_fuwu_organization_lng}';
        var lat = '{$o2o_fuwu_organization_info.o2o_fuwu_organization_lat}';
		if ('{$Think.config.ds_config.mapak_type}' === '1'){
			map = new AMap.Map("allmap", {
				resizeEnable: true,
				zoom:15
			});
			if(!lng && !lat){
				var map = new AMap.Map("allmap", {
					resizeEnable: true,
					zoom:15
				});
				//获取用户所在城市信息
					AMap.plugin("AMap.CitySearch", function () {
						var citySearch = new AMap.CitySearch();
						citySearch.getLocalCity(function (status, result) {
						  if (status === "complete" && result.info === "OK") {
							// 查询成功，result即为当前所在城市信息
							AMap.plugin("AMap.Geocoder", function () {
							  var geocoder = new AMap.Geocoder({
								// city 指定进行编码查询的城市，支持传入城市名、adcode 和 citycode
								city: result.adcode,
							  });
							  geocoder.getLocation(result.city, function(status1, result1) {
								  var location = result1.geocodes[0].location;
									var lng = location.lng;
									var lat = location.lat;
									
									//初始化定位
									var marker = new AMap.Marker({
										position: new AMap.LngLat(lng, lat),
										icon: '//api.map.baidu.com/images/marker_red_sprite.png',
										zoom: 15
									});
									map.add(marker);
									document.getElementById("longitude").value = lng;
									document.getElementById("latitude").value = lat;
									map.panTo([lng, lat]);
									
									//搜索定位
									AMap.plugin(['AMap.PlaceSearch','AMap.AutoComplete'], function(){
										var auto = new AMap.AutoComplete({input:"organization_address"});
										var placeSearch = new AMap.PlaceSearch({
											map: map
										});  //构造地点查询类
										auto.on("select", select);//注册监听，当选中某条记录时会触发
										function select(e) {
											placeSearch.setCity(e.poi.adcode);
											placeSearch.search(e.poi.name);  //关键字查询查询
										}
									});
									
									//点击定位
									map.on('click', function(e) {
										document.getElementById("longitude").value = e.lnglat.getLng();
										document.getElementById("latitude").value = e.lnglat.getLat();
										if(marker){
											map.remove(marker);
										}
										marker = new AMap.Marker({
											position: new AMap.LngLat(e.lnglat.getLng(), e.lnglat.getLat()),
											icon: '//api.map.baidu.com/images/marker_red_sprite.png',
											anchor: 'bottom-center',
											zoom: 15
										});
										map.add(marker);
									});
								});
							  
							});
							
						  }
						});
					  });
			}else{
				map.panTo([lng, lat]);
				//初始化定位
				var marker = new AMap.Marker({
					position: new AMap.LngLat(lng, lat),
					icon: '//api.map.baidu.com/images/marker_red_sprite.png',
					zoom: 15
				});
				map.add(marker);
				document.getElementById("longitude").value = lng;
				document.getElementById("latitude").value = lat;
				
				//搜索定位
				AMap.plugin(['AMap.PlaceSearch','AMap.AutoComplete'], function(){
					var auto = new AMap.AutoComplete({input:"organization_address"});
					var placeSearch = new AMap.PlaceSearch({
						map: map
					});  //构造地点查询类
					auto.on("select", select);//注册监听，当选中某条记录时会触发
					function select(e) {
						placeSearch.setCity(e.poi.adcode);
						placeSearch.search(e.poi.name);  //关键字查询查询
					}
				});
				
				//点击定位
				map.on('click', function(e) {
					document.getElementById("longitude").value = e.lnglat.getLng();
					document.getElementById("latitude").value = e.lnglat.getLat();
					if(marker){
						map.remove(marker);
					}
					marker = new AMap.Marker({
						position: new AMap.LngLat(e.lnglat.getLng(), e.lnglat.getLat()),
						icon: '//api.map.baidu.com/images/marker_red_sprite.png',
						anchor: 'bottom-center',
						zoom: 15
					});
					map.add(marker);
				});
			}		
		}
                if ('{$Think.config.ds_config.mapak_type}' === '2'){
			map = new BMap.Map("allmap");
			if(!lng && !lat){
				var geolocation = new BMap.Geolocation();
				geolocation.getCurrentPosition(function (r) {
					if (this.getStatus() == BMAP_STATUS_SUCCESS) {
						var lng = r.point.lng;
						var lat = r.point.lat;
						var point = new BMap.Point(lng, lat);
						map.centerAndZoom(point, 16);
						map.addControl(new BMap.NavigationControl());
						map.enableScrollWheelZoom();
						var marker = new BMap.Marker(point);  // 创建标注
						map.addOverlay(marker);              // 将标注添加到地图中
						marker.setAnimation(BMAP_ANIMATION_BOUNCE); //跳动的动画
						document.getElementById("longitude").value = lng;
						document.getElementById("latitude").value = lat;
	
					} else {
						layer.msg('failed' + this.getStatus());
					}
				}, {enableHighAccuracy: true})
			}else{
				var point = new BMap.Point(lng, lat);
				map.centerAndZoom(point, 16);
				map.addControl(new BMap.NavigationControl());
				map.enableScrollWheelZoom();
				var marker = new BMap.Marker(point);  // 创建标注
				map.addOverlay(marker);              // 将标注添加到地图中
				marker.setAnimation(BMAP_ANIMATION_BOUNCE); //跳动的动画
			}
	
	
			var options = {
				onSearchComplete: function(results){
					// 判断状态是否正确
					if (local.getStatus() == BMAP_STATUS_SUCCESS){
						if(results.getCurrentNumPois()>0){
	
							map.clearOverlays();  //清除标注  或者可以把market 放入数组
							var point = new BMap.Point(results.getPoi(0).point.lng , results.getPoi(0).point.lat);
							var marker = new BMap.Marker(point);
							map.centerAndZoom(point, 16);
							map.addOverlay(marker);
							marker.setAnimation(BMAP_ANIMATION_BOUNCE); //跳动的动画
	
							document.getElementById("longitude").value = results.getPoi(0).point.lng;
							document.getElementById("latitude").value = results.getPoi(0).point.lat;
	
						}
					}
				}
			};
			local = new BMap.LocalSearch(map, options);
			map.addEventListener("click", function(e){
	//                    alert(e.point.lng + ", " + e.point.lat);
				map.clearOverlays();  //清除标注  或者可以把market 放入数组
				var point = new BMap.Point(e.point.lng , e.point.lat);
				var marker = new BMap.Marker(point);
				map.addOverlay(marker);
				marker.setAnimation(BMAP_ANIMATION_BOUNCE); //跳动的动画
	
				document.getElementById("longitude").value = e.point.lng;
				document.getElementById("latitude").value = e.point.lat;
			});
		}
        
    })
    $(function () {
        $('#organization_birthday').datepicker({dateFormat: 'yy-mm-dd'});
        $("#region").ds_region();
        var url = '{:url("fuwu_manage_info/upload_info_file")}';
        $('#my_store_form').find('input[type="file"]').unbind().change(function () {
            var id = $(this).attr('id');
            ajaxFileUpload(url, id);
        });
    });

    function ajaxFileUpload(url, id)
    {
        $(document).off('change', "#file").on('change', function () {
            $.ajaxFileUpload({
                url: url,
                secureuri: false,
                fileElementId: id,
                dataType: 'json',
                data: {type: 'avatar'},
                success: function (data)
                {
                    if (data.code!=10000) {
                        layer.msg(data.message)
                    } else {
                        $("#img_" + id).attr('src', data.result.url);
                    }
                },
                error: function (data, status, e)
                {
                    console.error(data);
                }
            })
            return false;
        });
    }
</script>    


{/block}
